<?php

class RegionController extends AdminController {    
    
    public function actionIndex() {
        $model = new Region('search');
        $model->unsetAttributes();  // clear any default values
        if (isset($_GET['Region']))
            $model->attributes = $_GET['Region'];
        $this->render('index', array(
          'model' => $model,
        ));
	
    }
    
    function actions() {
        return array(
          'create' => array(
            'class' => 'lib.components.actions.CreateAction',
            'modelClass' => 'Region',
            'messages' => array('success' => t('MSG_INFO_INSERT_SUCCESS', 'messages' , array('{0}' => t('LBL_REGION','region'))))
          ),
          'update' => array(
            'class' => 'lib.components.actions.UpdateAction',
            'modelClass' => 'Region',
            'messages' => array('success' => t('MSG_INFO_UPDATE_SUCCESS', 'messages', array('{0}' => t('LBL_REGION','region'))))
          ),
          'delete' => array(
            'class' => 'lib.components.actions.DeleteAction',            
            'ajaxView' => "//share/_delete",
            'messages' => array('success' => t('MSG_INFO_DELETE_SUCCESS', 'messages' , array('{0}' => t('LBL_REGION','region'))))
          ),
          'error' => array(
            'class' => 'lib.components.actions.ErrorAction',
          ),
        );
    }
	
    public function actionGetAllOperation(){
        
        $allcontrollers = Region::model()->getAllController();
        $actions = array();
        foreach ($allcontrollers as $key => $controller) {
             $class = $controller."Controller";
                
                $hascombine =  method_exists ( $class , 'actions' );
                array_push($actions,$controller.'.'.'*');
                if($hascombine == 1){
                    $combinedActions = call_user_func(array($class, 'actions'));
                    foreach ($combinedActions as $key => $value){
                        array_push($actions,$controller.".".ucfirst($key));
                    }
                }

                $allmethods =get_class_methods($class);
                foreach ($allmethods as $key => $value){
                    if(strlen(strstr($value,'action'))>0){
                        if($value != 'actions'){
                            $value = str_replace('action', '', $value);
                            array_push($actions,$controller.".".ucfirst($value));
                        }
                    }
                }
        }
        echo CJSON::encode($actions);
    }
    
    public function loadModel() {
        $model = null;
        if (isset($_GET['id']))
        {
            $ids = explode(',', $_GET['id']);
            if (isset($ids)) {
                $criteria = new CDbCriteria;
                $criteria->addInCondition('id', $ids);
                $model = Region::model()->findAll($criteria);
            }         
        }
        return $model;
        
    }

    public function editDialogButtonHtml($regionModel, $dialogTitle, $dialogWidth, $dialogHeight) {
	$updateUrl = url(app()->controller->id . "/update/" . $regionModel->id);

	return Html::buttonInGrid('linkEdit', $updateUrl, 'Edit', $dialogTitle, 'icon edit update-dialog-open-link', $dialogWidth, $dialogHeight);
    }
}

?>